package com.coco.thread.start;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 方式4通过线程池的方式创建
 */
public class WayThread04 {
    private static int POOL_NUM = 10; //线程池数量

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(5);

        for(int i = 0; i<POOL_NUM; i++) {
            RunnableThread thread = new RunnableThread();
            executorService.execute(thread);
        }
        //关闭线程池
        executorService.shutdown();
    }

    static class RunnableThread implements Runnable {
        public void run() {
                System.out.println("通过线程池方式创建的线程：" + Thread.currentThread().getName() + " ");
        }
    }


}
